#define _CRT_SECURE_NO_WARNINGS 1
class Solution {
public:
    int maxSubArray(vector<int>& nums)
    {
        int size = nums.size();
        vector<int> dp(size + 1, 0);
        int res = nums[0];

        for (int i = 1; i < size + 1; i++)
        {
            dp[i] = max(dp[i - 1] + nums[i - 1], nums[i - 1]);
            res = max(res, dp[i]);
        }
        return res;
    }
};